package com.sgb.kjwl.view.ui.adapter.packers;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.sgb.kjwl.R;
import com.sgb.kjwl.view.ui.activity.PhotoViewActivity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.io.Serializable;
import java.util.List;

public class PresonIntroAdapter extends BaseRecycleAdapter<String> {

    public PresonIntroAdapter(Context context, List<String> filePath) {
        super(context, R.layout.item_preson_intro, filePath);
    }

    @Override
    public void convert(ItemViewHolder holder, String filePath) {
        ImageView imageviews = holder.itemView.findViewById(R.id.imageviews);
        RoundedCorners roundedCorners = new RoundedCorners(2);
//通过RequestOptions扩展功能,override采样率,因为ImageView就这么大,可以压缩图片,降低内存消耗
        RequestOptions options = new RequestOptions()
                .bitmapTransform(roundedCorners).override(300, 300)
                .placeholder(R.drawable.null_img_list)//图片加载出来前，显示的图片
                .error(R.drawable.shop_default);//图片加载失败后，显示的图片
        Glide.with(context)
                .load(filePath)
                .apply(options)//异常时候显示的图片
                .into(imageviews);
        imageviews.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, PhotoViewActivity.class);
                intent.putExtra(PhotoViewActivity.KEY_PHOTO_URLS, (Serializable) getDatas());
                intent.putExtra(PhotoViewActivity.KEY_PHOTO_POSITION, holder.getAdapterPosition());
               context.startActivity(intent);
            }
        });

    }
}
